<?php


namespace app\addons\aspect;


use app\cms\model\addons\addonsModel;
use iflow\aop\Abstracts\AbstractAspect;
use iflow\aop\Annotation\Aspect;

#[Aspect([
    'app\\addons\\lib\\*'
])]
class Addons extends AbstractAspect
{
    public function process(\Closure $closure, array $args = []): mixed
    {
        // TODO: Implement process() method.
        $addonsRule = explode('/', router()['rule'])[1] ?? '';
        if (!$addonsRule) {
            return message() -> nodata('未知插件信息');
        }

        $addons = (
            new addonsModel()
        ) -> findInfo(['addons_alis_rule' => $addonsRule]);
        if (!$addons) {
            return message() -> nodata('当前插件服务不存在');
        }

        if (intval($addons['status']) === 0) {
            return message() -> nodata('当前插件已停用');
        }

        return $closure(...$args);
    }
}